<template>
	<view>
		<view class="content-block">
			<view class="option-lst-block">
				<view class="item-option">
					<view class="left-label">即开入站<span>*</span></view>
					<input class="input-class" v-model="param.data0" placeholder="请输入您的即开入站" placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">即开调出<span>*</span></view>
					<input class="input-class" v-model="param.data1" placeholder="请输入您的即开调出" placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">备用金<span>*</span></view>
					<input class="input-class" v-model="param.data2" placeholder="请输入您的备用金" placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">传统机销售<span>*</span></view>
					<input class="input-class" v-model="param.data3" placeholder="请输入您的传统机销售" placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">传统机电票兑奖<span>*</span></view>
					<input class="input-class" v-model="param.data4" placeholder="请输入您的传统机电票兑奖"
						placeholder-class="pls" />
				</view>


				<view class="item-option">
					<view class="left-label">安卓机销售<span>*</span></view>
					<input class="input-class" v-model="param.data5" placeholder="请输入您的安卓机销售" placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">安卓机手续费<span>*</span></view>
					<input class="input-class" v-model="param.data6" placeholder="请输入您的安卓机手续费"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">竞彩销售<span>*</span></view>
					<input class="input-class" v-model="param.data7" placeholder="请输入您的竞彩销售" placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">竞彩本月销售<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="param.data9" placeholder="请输入您的竞彩本月销售"
						placeholder-class="pls" />
				</view>


				<view class="item-option">
					<view class="left-label">电票销售<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="teleticketing" placeholder="请输入您的电票销售"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">电票本月销售<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="param.data10" placeholder="请输入您的电票本月销售"
						placeholder-class="pls" />
				</view>


				<view class="item-option">
					<view class="left-label">建行收款<span>*</span></view>
					<input class="input-class" v-model="param.data11" placeholder="请输入您的建行收款" placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">企业微信收款<span>*</span></view>
					<input class="input-class" v-model="param.data26" placeholder="请输入您的企业微信收款"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">现金收款<span>*</span></view>
					<input class="input-class" v-model="param.data27" placeholder="请输入您的现金收款款"
						placeholder-class="pls" />
				</view>


				<view class="item-option">
					<view class="left-label">收款笔数<span>*</span></view>
					<input class="input-class" v-model="param.data12" placeholder="请输入您的收款笔数" placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">收款客单<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="billOfAccount" placeholder="请输入您的收款客单"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">销售客单<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="salesAccount" placeholder="请输入您的销售客单"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">传统机即开兑奖<span>*</span></view>
					<input class="input-class" v-model="param.data15" placeholder="请输入您的传统机即开兑奖"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">昨日即开库存<span>*</span></view>
					<input class="input-class" v-model="param.data16" placeholder="请输入您的昨日即开库存"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">今日即开库存<span>*</span></view>
					<input class="input-class" v-model="param.data17" placeholder="请输入您的今日即开库存"
						placeholder-class="pls" />
				</view>
				<view class="item-option">
					<view class="left-label">今日派奖<span>*</span></view>
					<input class="input-class" v-model="param.data18" placeholder="请输入您的今日派奖" placeholder-class="pls" />
				</view>
				<view class="item-option" v-if="userType==1">
					<view class="left-label">店员输入金额<span>*</span></view>
					<input class="input-class" v-model="param.data30" placeholder="请输入您的店员输入金额"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">充值<span>*</span></view>
					<input class="input-class" v-model="param.data33" placeholder="请输入您的充值" placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">购入即开<span>*</span></view>
					<input class="input-class" v-model="param.data28" placeholder="请输入您的购入即开" placeholder-class="pls" />
				</view>

				<view class="item-option" v-if="userType==1">
					<view class="left-label">电彩佣金<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="videoColorCommission" placeholder="请输入您的电彩佣金"
						placeholder-class="pls" />
				</view>
				<view class="item-option" v-if="userType==1">
					<view class="left-label">竞彩佣金<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="competitionCommission" placeholder="请输入您的竞彩佣金"
						placeholder-class="pls" />
				</view>



				<view class="item-option">
					<view class="left-label">今日差额<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="todaysBalance" placeholder="请输入您的今日差额"
						placeholder-class="pls" />
				</view>
				<view class="item-option" v-if="userType==1">
					<view class="left-label">差额<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="difference" placeholder="请输入您的差额"
						placeholder-class="pls" />
				</view>
				<view class="item-option" v-if="userType==0">
					<view class="left-label">账户余额<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="param.data21" placeholder="请输入您的账户余额"
						placeholder-class="pls" />
				</view>
				<view class="item-option" v-if="userType==1">
					<view class="left-label">当日账户余额<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="currentAccountBalance"
						placeholder="请输入您的当日账户余额" placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">今日即开销量<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="salesAreOpenToday" placeholder="请输入您的今日即开销"
						placeholder-class="pls" />
				</view>


				<view class="item-option">
					<view class="left-label">即开本月销售<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="param.data24" placeholder="请输入您的即开本月销售"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">今日总销量<span>*</span></view>
					<input class="input-class" :disabled="true" v-model="grossSalesToday" placeholder="请输入您的今日总销量"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">本月总销量<span>*</span></view>
					<input class="input-class" v-model="monthForTheSales" :disabled="true" placeholder="请输入您的本月总销量"
						placeholder-class="pls" />
				</view>

				<view class="item-option">
					<view class="left-label">备注信息<span>*</span></view>
					<input class="input-class" v-model="param.remark" placeholder="请输入您的备注信息" placeholder-class="pls" />
				</view>
			</view>

			<view class="submit">
				<view class="btn-submit cancel" @click="cancelClick">
					重置
				</view>
				<view class="btn-submit" @click="submitClick">
					确认
				</view>
			</view>
			<view style="height: 100rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				param: {
					stationId: '',
					data0: '', //即开入站
					data1: '', //即开调出
					data2: '', //备用金
					data3: '', //传统机销售
					data4: '', //传统机电票兑奖
					data5: '', //安卓机销售
					data6: '', //安卓机手续费
					data7: '', //竞彩销售
					data8: '', //电票销售
					data9: '', //竞彩本月销售
					data10: '', //电票本月销售
					data11: '', //建行收款
					data12: '', //收款笔数
					data13: '', //收款客单
					data14: '', //销售客单
					data15: '', //传统机即开兑奖
					data16: '', //昨日即开库存
					data17: '', //今日即开库存
					data18: '', //今日派奖
					data19: '', //电彩佣金
					data20: '', //竞彩佣金
					data21: '', //账户余额
					data22: '', //今日差额
					data23: '', //今日即开销量
					data24: '', //即开本月销量
					data25: '', //今日总销量
					data26: '', //企业微信收款
					data27: '', //现金收款
					data28: '', //购入即开 ==机器出票
					data29: '', //当日账户余额
					data30: '', //店员输入金额
					data31: '', //本月总销量
					data32: '', //差额
					data33: '', //充值
					remark: '', //备注
					status: 0, //0待审核 1已驳回 2已审核
					updateTime: 0, //更新时间
					createTime: 0, //创建时间
					dayTime: 0,
				},
				type: 0, //0添加 1是修改
				userType: 1, //类型0法人，1自然人
				yesterdayData29: 0, //昨天当日余额
			}
		},

		computed: {
			//电票销售
			teleticketing() {
				let data3 = this.param.data3 || 0
				let data5 = this.param.data5 || 0
				let data7 = this.param.data7 || 0

				let totalNums = this.accAdd(data3, data5)
				let res = this.accAdd(totalNums, -data7)
				this.param.data8 = res
				return res
			},
			//收款客单
			billOfAccount() {
				let data11 = this.param.data11 || 0
				let data12 = this.param.data12 || 0
				let res = this.accDiv(data11, data12)
				this.param.data13 = res
				return res
			},
			//销售客单
			salesAccount() {
				let data25 = this.param.data25 || 0
				if (data25) {
					let data12 = this.param.data12 || 0
					let res = this.accDiv(data25, data12)
					this.param.data14 = res
					return res
				} else {
					return 0
				}

			},
			//今日差额
			todaysBalance() {
				let data15 = this.param.data15 || 0 //传统机即开兑奖
				let data17 = this.param.data17 || 0 //今日即开库存

				let data18 = this.param.data18 || 0 //今日派奖
				let data26 = this.param.data26 || 0 //企业微信收款

				let data27 = this.param.data27 || 0 //现金收款
				let data3 = this.param.data3 || 0 //传统机销售
				let data4 = this.param.data4 || 0 //传统机电票兑奖

				let data2 = this.param.data2 || 0 //备用金

				let data1 = this.param.data1 || 0 //即开调出
				let data11 = this.param.data11 || 0 //建行收款


				let data16 = this.param.data16 || 0 //昨日即开库存

				let data0 = this.param.data0 || 0 //即开调出

				let strOne = this.accAdd(data15, data17) //传统机即开兑奖+今日即开库存

				let strTwo = this.accAdd(data18, data26) //今日派奖+企微收款


				let strThree = this.accAdd(strOne, strTwo) // strOne+strTwo

				let strFour = this.accAdd(strThree, data27)


				let strFive = this.accAdd(strFour, -data3)

				let strSix = this.accAdd(strFive, data4)

				let strSeven = this.accAdd(strSix, -data2)


				let strEngiht = this.accAdd(strSeven, data1)

				let strTen = this.accAdd(strEngiht, data11)


				let strNine = this.accAdd(data16, data0)

				let total = this.accAdd(strTen, -strNine)

				this.param.data22 = total
				return total
			},
			//今日即开销量
			salesAreOpenToday() {
				//昨日即开库存 没有字段
				let data16 = this.param.data16 || 0 //昨日即开库存
				let data0 = this.param.data0 || 0 //即开入站
				let data17 = this.param.data17 || 0 //今日即开库存
				let data1 = this.param.data1 || 0 //即开调出

				let strOne = this.accAdd(data16, data0)
				let strTwo = this.accAdd(strOne, -data17)
				let res = this.accAdd(strTwo, -data1)
				this.param.data23 = res
				return res
			},
			//今日总销售
			grossSalesToday() {
				let data3 = this.param.data3 || 0 //传统机销售
				let data5 = this.param.data5 || 0 //安卓机销售

				let data16 = this.param.data16 || 0 //昨日即开库存
				let data0 = this.param.data0 || 0 //即开入站

				let data17 = this.param.data17 || 0 //今日即开库存
				let data1 = this.param.data1 || 0 //即开调出

				let strOne = this.accAdd(data3, data5)

				let strTwo = this.accAdd(data16, data0)


				let strThree = this.accAdd(strOne, strTwo)

				let oneAndTwoTotal = this.accAdd(strThree, -data17)

				let res = this.accAdd(oneAndTwoTotal, -data1)
				this.param.data25 = res
				return res

			},
			//本月总销量 data31
			monthForTheSales() {
				let data9 = this.param.data9 || 0 //竞彩本月销售
				let data10 = this.param.data10 || 0 //电票本月销售
				let data24 = this.param.data24 || 0 //即开本月销量
				let strOne = this.accAdd(data9, data10)
				let res = this.accAdd(strOne, data24)
				return res
			},
			//电彩佣金
			videoColorCommission() {
				let data8 = this.param.data8 || 0

				let res = this.accMul(data8, 0.085)
				this.param.data8 = res
				return res

			},
			//竞彩佣金
			competitionCommission() {
				let data7 = this.param.data7 || 0

				let res = this.accMul(data7, 0.07);
				this.param.data20 = res
				return res

			},
			//当日账户余额
			currentAccountBalance() {
				let yesterdayData29 = this.yesterdayData29 || 0 //前日账户余额
				let data33 = this.param.data33 || 0 //充值
				let data28 = this.param.data28 || 0 //购入即开
				let data3 = this.param.data3 || 0 //传统机销售
				let data4 = this.param.data4 || 0 //传统机兑奖
				let data15 = this.param.data15 || 0 //传统机即开兑奖

				let data6 = this.param.data6 || 0 //安卓机手续费
				let strOne = this.accAdd(yesterdayData29, data33)

				let strTwo = this.accAdd(strOne, -data28)
				let strThree = this.accAdd(strTwo, -data3)
				let strFour = this.accAdd(strThree, data4)

				let strFive = this.accAdd(strFour, data15)
				let res = this.accAdd(strFive, -data6)

				this.param.data29 = res
				this.param.data21 = res
				return res
			},
			//差额
			difference() {
				let data29 = this.param.data29 || 0
				let data30 = this.param.data30 || 0
				let res = this.accAdd(data29, -data30);
				this.param.data32 = res
				return res
			}
		},
		onLoad(e) {
			if (e) {
				if (e.type == 0) {
					this.type = 0
					//添加
					// this.cancelClick()
				} else {
					//编辑
					this.type = 1
					let billParam = uni.getStorageSync('billItem')
					console.log('billParam========', billParam)
					this.param = billParam
					this.param.data19 = 0
					this.param.stationEntity = null
				}
			}
		},
		onShow() {
			this.initTwo()
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				this.$http('user.getInformation', {
					token: this.$tools.getToken()
				}).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('userInfo', res.data.data)
						this.userInfo = res.data.data
						this.userType = this.userInfo.type
					}
				})
			},
			initTwo() {
				this.$http('manageMent.getHistoryBill', {
					token: this.$tools.getToken()
				}).then(res => {
					console.log('res=', res)
					if (res.code == 200) {
						this.param.data9 = res.data.data9 || 0
						this.param.data10 = res.data.data10 || 0
						// this.param.data16 = res.data.data16 || 0
						this.param.data24 = res.data.data24 || 0
						this.yesterdayData29 = res.data.data29 || 0
					}
				})
			},
			cancelClick() {
				this.param.stationId = ''
				this.param.data0 = ''
				this.param.data1 = ''
				this.param.data2 = ''
				this.param.data3 = ''
				this.param.data4 = ''
				this.param.data5 = ''
				this.param.data6 = ''
				this.param.data7 = ''
				this.param.data8 = ''
				this.param.data9 = ''
				this.param.data10 = ''
				this.param.data11 = ''
				this.param.data12 = ''
				this.param.data13 = ''
				this.param.data14 = ''
				this.param.data15 = ''
				this.param.data16 = ''
				this.param.data17 = ''
				this.param.data18 = ''
				this.param.data19 = 0
				this.param.data20 = ''
				this.param.data21 = ''
				this.param.data22 = ''
				this.param.data23 = ''
				this.param.data24 = ''
				this.param.data25 = ''
				this.param.data26 = ''
				this.param.data27 = ''
				this.param.data28 = ''
				this.param.data29 = ''
				this.param.data30 = ''
				this.param.data31 = ''
				this.param.data32 = ''
				this.yesterdayData29 = 0
				this.param.remark = ''
				this.param.status = 0
				this.param.updateTime = 0
				this.param.createTime = 0
				this.param.dayTime = 0
				this.initTwo()
			},
			submitClick() {
				let userInfo = uni.getStorageSync('userInfo')
				this.param.stationId = userInfo.id
				if (this.type == 0) {
					this.param.data8 = this.teleticketing
					this.param.data13 = this.billOfAccount
					this.param.data14 = this.salesAccount
					this.param.data22 = this.todaysBalance
					this.param.data23 = this.salesAreOpenToday
					this.param.data25 = this.grossSalesToday
					this.param.data24 = this.monthForTheSales
					this.param.data20 = this.competitionCommission
					this.param.data21 = this.currentAccountBalance
					this.param.data29 = this.currentAccountBalance
					this.param.data32 = this.difference
					this.$http('manageMent.addBill', {
						...this.param,
						token: this.$tools.getToken(),
					}).then(res => {
						this.$tools.showMsg(res.msg)
						if (res.code == 200) {
							setTimeout(() => {
								uni.navigateBack()
							}, 600)
						}
					})
				} else {
					this.param.dayTime = 0
					this.param.data8 = this.teleticketing
					this.param.data13 = this.billOfAccount
					this.param.data14 = this.salesAccount
					this.param.data22 = this.todaysBalance
					this.param.data23 = this.salesAreOpenToday
					this.param.data25 = this.grossSalesToday
					this.param.data24 = this.monthForTheSales
					this.param.data20 = this.competitionCommission
					this.param.data21 = this.currentAccountBalance
					this.param.data29 = this.currentAccountBalance
					this.param.data32 = this.difference
					console.log('===this.paramthis.paramthis.param====', this.param)
					this.$http('manageMent.upBill', {
						...this.param,
						token: this.$tools.getToken(),
					}).then(res => {
						this.$tools.showMsg(res.msg)
						if (res.code == 200) {
							setTimeout(() => {
								uni.navigateBack()
							}, 600)
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.content-block {
		margin-left: 24rpx;
		margin-right: 24rpx;
		margin-top: 24rpx;

		.user-img-block {
			padding-top: 40rpx;
			padding-bottom: 76rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			position: relative;

			.img-option {
				background: skyblue;
				width: 160rpx;
				height: 160rpx;
				border-radius: 50%;
			}

			.upload-img {
				position: absolute;
				width: 88rpx;
				height: 88rpx;
				left: 350rpx;
				top: 140rpx;
			}
		}



		.option-lst-block {

			background: #FFFFFF;
			border-radius: 8rpx;
			margin-bottom: 32rpx;

			.hint-option {
				display: flex;
				align-items: center;
				padding: 28rpx 0;

				// border-bottom: 1rpx solid #EFEFEF;

				.left-option {
					flex: auto;
					display: flex;
					align-items: center;

					.icon {
						width: 6rpx;
						height: 30rpx;
						background: linear-gradient(162deg, #7ABCF4 0%, #1B8BF6 100%);
						border-radius: 364rpx;
						margin-left: 20rpx;
					}

					.txt {
						margin-left: 16rpx;
						font-weight: 700;
						font-size: 32rpx;
						color: #000F18;
					}
				}

				.right-option {
					padding-right: 20rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #1B8BF6;
					flex: none;
				}
			}


			.item-option {
				margin-left: 32rpx;
				margin-right: 32rpx;
				padding: 44rpx 0;
				display: flex;
				align-items: center;
				border-bottom: 1rpx solid #EFEFEF;

				.left-label {
					font-weight: bold;
					font-size: 28rpx;
					// color: #666666;
					margin-right: 24rpx;

					span {
						color: red;
					}
				}

				.input-class {
					flex: auto;
					text-align: right;

				}

				.pls {
					font-weight: 400;
					font-size: 28rpx;
					color: #CCCCCC;
				}
			}

			.content-textares-block {
				margin-top: 24rpx;
				// width: 662rpx;
				height: 240rpx;
				margin-left: 24rpx;
				margin-right: 24rpx;
				padding: 24rpx;
				background: rgba(244, 245, 252, 0.7);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				display: flex;

				// align-items: center;
				.edit-icon {
					width: 26rpx;
					height: 26rpx;
				}

				.textCls {
					margin-left: 16rpx;
					height: 240rpx;
				}

				.textPls {
					font-weight: 400;
					font-size: 28rpx;
					color: #CCCCCC;
				}
			}

			.content-block {
				margin-top: 24rpx;
				width: 582rpx;
				margin-left: auto;
				margin-right: auto;
				height: 140rpx;
				background: #F4F5FC;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.add-icon {
					width: 32rpx;
					height: 32rpx;
				}

				.txt {
					padding-left: 21rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
				}
			}
		}
	}

	.submit {
		margin-left: 42rpx;
		margin-right: 42rpx;
		margin-top: 24rpx;

		border-radius: 8rpx 8rpx 8rpx 8rpx;
		display: flex;
		align-items: center;
		justify-content: space-evenly;

		.btn-submit {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #FFFFFF;
			font-size: 30rpx;
			width: 226rpx;
			height: 76rpx;
			border-radius: 8rpx;
			background: linear-gradient(153deg, #69C5FD 0%, #0089CF 63%);
		}

		.cancel {
			background: #fff;
			color: #7ABCF4;
			border: 1rpx solid #7ABCF4;
		}

		.check-login-fn {
			font-weight: 500;
			text-align: center;
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #FF6E15;
		}
	}
</style>